<template>
  <view class="cart-container" v-if="total">
    <!-- 收货地址 -->
    <my-adress></my-adress>
    <!-- 列表标题 -->
    <view class="cart-title">
      <!-- 左侧的图标 -->
      <uni-icons type="shop" size="18"></uni-icons>
      <!-- 右侧文本 -->
      <text class="cart-title-text">购物车</text>
    </view>

    <!-- 按组使用 -->
    <uni-swipe-action>
      <!-- 商品信息 -->
      <view v-for="(goods,i) in cart" :key="i" @click="goToDetail(goods)">
        <uni-swipe-action-item :right-options="options" @click="bindClick(goods)" @change="swipeChange($event, index)">
          <my-goods :showRadio="true" :showNumber="true" :goods="goods"></my-goods>
        </uni-swipe-action-item>
      </view>
    </uni-swipe-action>
    <!-- 结算 -->
    <my-settle></my-settle>
  </view>
  <!-- 空白 -->
  <view class="empty-cart" v-else>
    <image src="/static/cart-kong.png"></image>
    空空如也~
  </view>
</template>

<script>
  import minix from "@/minixs/tabbar-badge.js"
  import {
    mapState,
    mapMutations,
    mapGetters
  } from 'vuex'
  export default {
    mixins: [minix],
    computed: {
      ...mapState('m_cart', ['cart']),
      ...mapGetters('m_cart', ['total'])
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#dd524d'
          }
        }]
      };
    },
    methods: {
      ...mapMutations('m_cart', ['delGoods']),
      goToDetail(goods) {
        console.log(goods.goods_id)
        uni.navigateTo({
          url: '/subpkg/goods_detail/goods_detail?goods_id=' + goods.goods_id
        })
      },

      bindClick(goods) {
        this.delGoods(goods)
        console.log(goods)
      },
      swipeChange() {

      }
    }
  }
</script>

<style lang="scss">
  .cart-title {
    height: 40px;
    display: flex;
    align-items: center;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;

    .cart-title-text {
      font-size: 14px;
      margin-left: 6px;
    }
  }

  .cart-container {
    padding-bottom: 50px;
  }

  .empty-cart {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding-top: 120px;
  }
</style>